// Learn TypeScript:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

// 贪吃蛇的食物类
@ccclass
export default class Food extends cc.Component {


    // onLoad () {}

    start() {
        this.resetPosition();
    }

    resetPosition() {
        let minX = -this.node.parent.width/2 + this.node.width/2; //最小X坐标；
        let maxX = Math.abs(minX);
        let minY = -this.node.parent.height/2 + this.node.height/2; //最小Y坐标；
        let maxY = Math.abs(minY);
        let x = Math.floor(this.random(minX, maxX));
        let y = Math.floor(this.random(minY, maxY));
        this.node.x = x;
        this.node.y = y;
    }

    random(min, max) {
        return Math.random() * (max - min) + min;
    }

timer:number = 0 ;
    update(dt) {

    }

    onCollisionEnter(other,self){
        this.resetPosition();
    }
}
